package py.com.erpone.session.dm.list;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import py.com.erpone.entity.dm.Presentacion;
import py.com.erpone.entity.dm.Rol;
import py.com.erpone.entity.dm.Tarea;

@Stateless
@LocalBean
@Named
public class RolList {
	@PersistenceContext
	private EntityManager em;
	

	@SuppressWarnings("unchecked")
	public List<Rol> findAll(){
		List<Rol> result=(List<Rol>)em.createNamedQuery("rol.all").getResultList();
		return result;
	}
	
	@SuppressWarnings("unchecked")
	public List<Tarea>findAllTareas(long id){		
		

		String sql = " select p.* " +
				 " from Rol_Tarea b " +
				 " join Tarea p on b.tarea_id = p.id" +
				 " where b.Rol_id = ? " +
				 " order by b.Rol_id";
		
		Query query = em.createNativeQuery(sql, Tarea.class);
		query.setParameter(1, id);
		List<Tarea> result = query.getResultList();
		return result;
	} 
	
	public Rol findById(Long id){
		return em.find(Rol.class, id);
	}
}
